package com.itheima.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.pojo.OrderSetting;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

@Mapper
public interface OrderSettingMapper  extends BaseMapper<OrderSetting> {
    @Select("select  day(orderdate) as date , number ,reservations  from  t_ordersetting  where  ORDERDATE BETWEEN #{beginDate} and #{endDate}")
    List<Map> findOrderSettingsData(@Param("beginDate") String beginDate, @Param("endDate") String endDate);

    @Select("select  count(1)  from t_ordersetting where  ORDERDATE  = #{orderDate}  and  number>RESERVATIONS")
    int isOrderOk(@Param("orderDate") String orderDate);

    @Update("update  t_ordersetting  set  RESERVATIONS = RESERVATIONS+1 where ORDERDATE = #{orderDate}")
    void updateReservationsByOrderDate(@Param("orderDate") String orderDate);
}
